package com.链表;

/**
 * 找到两个单链表相交的起始节点。
 * https://leetcode-cn.com/problems/intersection-of-two-linked-lists/
 */
public class 相交链表 {
    public static ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode ha = headA, hb = headB;
        while (ha != hb) {
            ha = ha != null ? ha.next : headB;
            hb = hb != null ? hb.next : headA;
        }
        return ha;
    }

    public static void main(String[] args) {
        ListNode l1 = new ListNode(new int[]{1,2,3});
        ListNode l2 = new ListNode(new int[]{4,5,1});
        System.out.println(getIntersectionNode(l1,l2));

    }
}

